package com.smartfast4j.controller;

import com.mongodb.BasicDBObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by gacl on 2017/11/15.
 */
@WebServlet(name = "IndexServlet",urlPatterns = "/index")
public class IndexServlet extends HttpServlet {

    private  final Logger logger = LoggerFactory.getLogger(getClass());

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 基本信息
        BasicDBObject basicDBObject = new BasicDBObject();
        basicDBObject.put("requestURL", request.getRequestURL().toString());
        basicDBObject.put("requestURI", request.getRequestURI());
        basicDBObject.put("queryString", request.getQueryString());
        basicDBObject.put("remoteAddr", request.getRemoteAddr());
        basicDBObject.put("remoteHost", request.getRemoteHost());
        basicDBObject.put("remotePort", request.getRemotePort());
        basicDBObject.put("localAddr", request.getLocalAddr());
        basicDBObject.put("localName", request.getLocalName());
        basicDBObject.put("method", request.getMethod());
        basicDBObject.put("parameters", request.getParameterMap());
        logger.info(basicDBObject.toJson());
        response.getWriter().print(basicDBObject.toJson());
    }
}
